package File;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Ap0stoL2
 * Date: 2023-08-06
 * Time: 11:12
 */

//FileInputStream
public class Demo7 {
    public static void main(String[] args) throws IOException {

        //这里运用了多态,子类构造变成父类
        //文本文件也可以使用字节流打开,只不过你读到的每个字节就不是完整字符了
        try (InputStream inputStream = new FileInputStream("d:/test.txt")) {
            while (true) {
                byte[] buf = new byte[1024];
                int n = inputStream.read(buf);
                if (n == -1) {
                    break;
                } else {
                    for(int i=0;i<n;i++){
                        //字节一般用 16进制打印,%x打印16进制
                        System.out.printf("%x ",buf[i]);
                    }
                    System.out.println();

                }
                String s1 = new String(buf,0,n);
                System.out.println(s1);
            }


        }
    }
}
